/**
 *  REPORTS WINDOW
 *  SCREEN GENERICA PRA SER USADA PRA LISTAR INFORMACOES
 *  PARAMS:
 *  	COLNAMES: ARRAY COM OS NOMES DAS COLUNAS (A QUANTIDADE EH ESPECIFICADA PELO N DE ELEMENTOS)
 *  	DATA: ARRAY 2D COM AS INFORMACOES DA TABELA LINHA X COLUNA
 * 
 */
package br.com.hotel68.view.gui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableModel;

public class ReportsWindow extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5809347886461144065L;
	private JPanel contentPane;
	private JTable dataTable;

	
	public ReportsWindow(String[] colNames,String[][] data){
		
		dataTable = new JTable(data, colNames);
		initialize();
		this.setVisible(true);
	}
	
	/**
	 * @wbp.parser.constructor
	 */
	public ReportsWindow(TableModel tableModel){
		
		dataTable = new JTable(tableModel);
		dataTable.sizeColumnsToFit(1);
		initialize();
		this.setVisible(true);
	}

	/**
	 * Create the frame.
	 */
	public void initialize() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 600, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		contentPane.add(panel, BorderLayout.NORTH);
		
		JLabel lblReportTitle = new JLabel("Report Title");
		lblReportTitle.setFont(new Font("Tahoma", Font.BOLD, 12));
		panel.add(lblReportTitle);
		
		JScrollPane scrollPane = new JScrollPane();
		contentPane.add(scrollPane, BorderLayout.CENTER);
		
		dataTable.setEnabled(false);
		scrollPane.setViewportView(dataTable);
		
		JPanel panel_1 = new JPanel();
		FlowLayout flowLayout_1 = (FlowLayout) panel_1.getLayout();
		flowLayout_1.setAlignment(FlowLayout.RIGHT);
		contentPane.add(panel_1, BorderLayout.SOUTH);
		
		JButton btnImprimir = new JButton("Imprimir");
		btnImprimir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				printReport();
			}
		});
		panel_1.add(btnImprimir);
	}
	
	public void printReport(){
		try {
			dataTable.print();
		} catch (PrinterException e) {
			JOptionPane.showMessageDialog(this,"Não foi possível imprimir o documento!","ATENÇÃO",JOptionPane.ERROR_MESSAGE);
		}
	}

}
